# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.shortcuts import render,HttpResponseRedirect
from appBlog2.models import *
from appBlog2.forms import *
from django.utils.translation import ugettext as _

# Create your views here.

def poem_list(request):
	# foo = _('test langauge ')
	return render(request,'poem_list.html',{'poems':Poem.objects.all()},{'foo':_('test langauge')})

def testlist(request):
	test = ListTest()
	test.labels = ['python','django']
	test.labels.append('admin')
	test.save()
	obs = ListTest.objects.all()
	for ob in obs:
		print ob.labels
	return HttpResponseRedirect('/')

def addfile(request):
	if request.method =='POST':
		addpdf_form = AddPdfForm(request.POST,request.FILES)
		if not addpdf_form.is_valid():
			return HttpResponseRedirect('/')
		name = addpdf_form.cleaned_data['name']
		file = addpdf_form.cleaned_data['file']
		add_pdf_model = AddPdfFileModel(name=name,file=file)
		add_pdf_model.save()
		return render(request, 'add_file.html', {'form':addpdf_form})
	else:
		addpdf_form = AddPdfForm()
		return render(request,'add_file.html',{'form':addpdf_form})
